package com.ggh.jinjilive.ui.mall.order;

import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityOrderBinding;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.ui.mall.MallFragment;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.gyf.immersionbar.ImmersionBar;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;


/**
 * 我的订单
 */
@Route(path = ARouterUtils.OrderActivity)
public class OrderActivity extends BaseActivity<ActivityOrderBinding> {
    //跳转到那个
    public int index = 0;
    public int type = 0;
    //
    private String[] mFragmentTitles = {"我的订单", "待付款","待发货","待收货","售后服务"};
    //
    private ProfitOrderAdapter profitOrderAdapter;
    //

    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).init();
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_order;
    }

    @Override
    public void initParam() {
        super.initParam();
        index = getIntent().getExtras().getInt("index", 0);
        type = getIntent().getExtras().getInt("type", 0);
    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("我的订单",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);
        //适配器
        profitOrderAdapter = new ProfitOrderAdapter(getSupportFragmentManager());
        binding.vp.setAdapter(profitOrderAdapter);
        binding.stlOrder.setViewPager(binding.vp, mFragmentTitles);
        binding.vp.setCurrentItem(index);
    }


    class ProfitOrderAdapter extends FragmentPagerAdapter {

        public ProfitOrderAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return new OrderFragment(position,type);
        }

        @Override
        public int getCount() {
            return 5;
        }

        @Override
        public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
//            super.destroyItem(container, position, object);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles[position];
        }

        @Override
        public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            super.setPrimaryItem(container, position, object);
        }
    }
}
